<template>
  <div class="home-container">
    <div class="home-tou">
      <!-- 导航栏 -->
      <van-nav-bar fixed>
        <template #title>
          <van-button
            type="info"
            size="small"
            round
            icon="search"
            class="page_nav_bar"
            >搜索
          </van-button>
        </template>
      </van-nav-bar>
      <!-- /导航栏 -->
    </div>
    <!-- 频道列表 -->
    <van-tabs
      v-model="active"
      animated
      swipeable
      class="channelTabs"
      :lazy-render="false"
    >
      <van-tab
        :title="channel.name"
        :key="channel.id"
        v-for="channel in channels"
      >
        <!-- 组件区域 -->
        <article-list :channel="channel"></article-list>
      </van-tab>
      <template #nav-right>
        <div slot="nav-right" class="placeholder"></div>
        <div slot="nav-right" class="hamburger-btn">
          <i
            class="toutiao toutiao-gengduo"
            @click="isEditChannelShow = true"
          ></i>
        </div>
      </template>
    </van-tabs>
    <!-- /频道列表 -->
    <!-- 频道编辑弹出层 -->
    <van-popup
      class="edit-channel-popup"
      v-model="isEditChannelShow"
      closeable
      position="bottom"
      :style="{ height: '100%' }"
      close-icon-position="top-left"
      ><channel-edit></channel-edit>
    </van-popup>
    <!-- /频道编辑弹出层 -->
  </div>
</template>

<script>
import { getUserChannels } from '@/api/user'
import ArticleList from './components/article-list'
import ChannelEdit from './components/channel-edit'
export default {
  name: 'HomeIndex',
  props: {},
  data() {
    return {
      active: 0,
      channels: [],
      isEditChannelShow: false // 这里我们先设置为 true 就能看到弹窗的页面了
    }
  },
  methods: {
    async loadChannels() {
      try {
        const { data } = await getUserChannels()
        this.channels = data.data.channels
      } catch (err) {
        this.$toast('获取数据失败，请稍后重试')
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.loadChannels()
  },
  mounted() {},
  components: {
    ArticleList,
    ChannelEdit
  }
}
</script>

<style scoped lang="less">
// ::deep或者/deep/具有穿透作用，可以影响父元素，忽略scoped属性
.home-container {
  margin-top: 88px;
  ::v-deep .van-nav-bar__title {
    max-width: unset;
    //   unset相当于不设置
  }
  .page_nav_bar {
    width: 278px;
    height: 32px;
    background-color: #5babfb;
    border: none;
    font-size: 18px;
    .van-icon {
      font-size: 23px;
    }
  }
  ::v-deep .channelTabs {
    .van-tabs__wrap {
      height: 41px;
      position: fixed;
      top: 46px;
      border-bottom: 1px solid #edeff3;
      z-index: 2;
      right: 0;
      left: 0;
    }
    .van-tab {
      min-width: 100px;
      border-right: 1px solid #edeff3;
      font-size: 14px;
      color: #777;
    }
    .van-tab--active {
      color: #333;
    }
    .van-tabs__nav {
      padding-bottom: 0;
    }
    .van-tabs__line {
      bottom: 8px;
      width: 16px;
      height: 3px;
      background-color: #3296fa;
    }
    .edit-channel-popup {
      padding-top: 50px;
      box-sizing: border-box;
    }
    .placeholder {
      flex-shrink: 0;
      width: 33px;
      height: 41px;
    }
    .hamburger-btn {
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 42px;
      height: 41px;
      background-color: #fff;
      opacity: 0.902;
      i.toutiao {
        font-size: 12px;
      }
      &:before {
        content: '';
        position: absolute;
        left: 0;
        width: 1px;
        height: 100%;
        background-image: url(~@/assets/gradient-gray-line.png);
        background-size: contain;
      }
    }
  }
}
</style>
